{include file="common/header"/}
<style type="text/css">
    /* 仅作用于表格内容部分（tbody内的单元格） */
    tbody .layui-table-cell {
        overflow: visible;
        height: 80px;
    }
</style>
<div class="lemo-container">
    <div class="lemo-main">
        <div class="admin-main layui-anim layui-anim-upbit">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>进货表</legend>
                <blockquote class="layui-elem-quote">
                    <div class="layui-inline">
                        <input type="text" id='keys' name="keys" lay-verify="required" placeholder="{:lang('pleaseEnter')}" autocomplete="off" class="layui-input">
                    </div>
                    <a href="javascript:;" class="layui-btn data-add-btn layui-btn-sm" lay-submit="" lay-filter="search" id="search">{:lang('search')}</a>
                    <a data-href='{:url("add")}' href="javascript:;" class="layui-btn layui-btn-sm layui-btn-warm add">{:lang('add')}</a>
                </blockquote>
            </fieldset>
            <table class="layui-table" id="list" lay-filter="list"></table>
        </div>
    </div>
</div>

<script type="text/html" id="action">
    <a  class="layui-btn layui-btn-danger layui-btn-xs" data-href="{:url('delete')}?id={{d.id}}" lay-event="del">{:lang('del')}</a>
</script>
<script type="text/html" id="status">
    {{# if(d.status ==1) {}}
        已审核
    {{# } else if (d.status ==2) {}}
        驳回
    {{# } else {}}
    未审核
    {{# }}}
</script>

<script type="text/html" id="imgurl">
    <img class="layui-upload-img" id="addPic" src="{{d.pic}}" width="80px" height="80px">
</script>

{include file="common/footer"/}
<script>
    var tableIn=null;
    layui.config({
        base: "/static/admin/js/",
        version: true
    }).extend({
        Admin: 'Admin'
    }).use(['form', 'table','Admin'], function () {
        var table = layui.table;
        tableIn = table.render({
            elem: '#list',
            url: '{:url("index")}',
            method: 'post',
            lineStyle: 'height:auto',
            done: function() {
                // 同步固定列高度
                $('img').css('overflow', 'auto');
            },
            cols: [[
                {field: 'id', title: 'ID', width: 80,  sort: true},
                {field: 'pic', title: '图片', width: 100,toolbar: '#imgurl'},
                {field: 'name', title: '产品名称', width: 120,sort: true},
                {field: 'material', title: '规则材质', width: 120,sort: true},
                {field: 'box_gauge', title: '箱规', width: 120,sort:true},
                {field: 'manufacturer', title: '厂家名称', width: 120,sort:true},
                {field: 'num', title: '数量', width: 120,sort: true},
                {field: 'buying_price', title: '进货价', width: 120,sort: true},
                {field: 'notes', title: '备注', width: 160,sort: true},
                {field: 'price_adjustment_date', title: '调价日期', width: 170,
                templet: function(d){
                    var str = '';
                    d.adjustment.forEach((value) => {
                        str += `调价${value.price} 用户:${value.user} 日期:${value.price_adjustment_date} <br>`;
                    })
                    return `<span class="name-cell" data-length="${d.adjustment.length}" data-price="${str}">${d.price_adjustment_date}</span> <a data-href="{:url('addAdjustment')}?id=${d.id}" class="layui-btn  layui-btn-xs" lay-event="tiaojia">调价</a>`;
                    }
                },
                {field: 'uid', title: '录入人', width: 120,sort: true},
                {field: 'create_time', title: '创建时间', width: 170,sort:true},
                {title:'操作',width:120, toolbar: '#action',align:"center"}
            ], 
        ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
        });

        let tipIndex = null;

        document.addEventListener('mouseover', function(e){
        if (e.target.classList.contains('name-cell')) {
            const content = e.target.getAttribute('data-price');
            let length = e.target.getAttribute('data-length');
            let line_num = Number.parseInt(length);
            let px = line_num*23 + 10;
            if (content) {
                tipIndex = layer.tips(content, e.target, {
                    tips: [1, '#3595CC'],
                    time: 0,
                    area: ['240px', `${px}px`],
                });
            }
        }
        });

        document.addEventListener('mouseout', function(e){
            if (e.target.classList.contains('name-cell') && tipIndex !== null) {
            layer.close(tipIndex);
            tipIndex = null;
            }
        });
    });


</script>